package com.gene.service.impl;

import com.gene.mapper.AreaRecordMapper;
import com.gene.pojo.AreaRecord;
import com.gene.pojo.AreaRecordExample;
import com.gene.service.IAreaRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AreaRecordServiceImpl implements IAreaRecordService {
    @Autowired
    private AreaRecordMapper areaRecordMapper;

    @Override
    public List<AreaRecord> query(AreaRecord areaRecord) {
        AreaRecordExample example=new AreaRecordExample();
        AreaRecordExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(areaRecord.getUserId());
        example.setOrderByClause("ctime DESC");
        List<AreaRecord> list = areaRecordMapper.selectByExample(example);
        return list;
    }

    @Override
    public boolean add(AreaRecord areaRecord) {
        areaRecord.setCtime(new Date());
        int a=areaRecordMapper.insert(areaRecord);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(AreaRecord areaRecord) {
        int a=areaRecordMapper.updateByPrimaryKeySelective(areaRecord);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(AreaRecord areaRecord) {
        int a=areaRecordMapper.deleteByPrimaryKey(areaRecord.getRecordId());
        if(a==1){
            return true;
        }
        return false;
    }
}
